package com.gist.cithub.service.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gist.cithub.service.entity.HistorylistEntity;
import com.gist.cithub.service.service.HistorylistService;
import com.gist.common.utils.PageUtils;
import com.gist.common.utils.R;



/**
 * 服务历史版本
 *
 * @author lejin
 * @email sunlightcs@gmail.com
 * @date 2020-11-23 13:29:16
 */
@RestController
@RequestMapping("service/historylist")
public class HistorylistController {
    @Autowired
    private HistorylistService historylistService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = historylistService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 信息
     */
    @RequestMapping("/getHistoryByServiceId/{serviceId}")
    public R getHistoryByServiceId(@PathVariable("serviceId") Integer serviceId){
        List<HistorylistEntity> list = historylistService.getHistoryByServiceId(serviceId);

        return R.ok().put("list", list);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		HistorylistEntity historylist = historylistService.getById(id);

        return R.ok().put("historylist", historylist);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HistorylistEntity historylist){
		historylistService.save(historylist);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HistorylistEntity historylist){
		historylistService.updateById(historylist);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		historylistService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
